home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 927 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: martin@kcbbs.gen.nz (Martin D Kealey)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: constness of private members and methods
  5. Date: 01 Apr 1996 10:39:46 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <m0u3992-000GcEC@7.kurahaupo.gen.nz>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. Content-Type: text/plain; charset=ISO-8859-1
  11. Content-Transfer-Encoding: 8bit
  12. X-Original-Date: Sun, 31 Mar 1996 10:29:15 +1200 (NZST)
  13. In-Reply-To: <4j7tfi$1npo@mule1.mindspring.com> from "Andrew Bell" at Mar 26, 96 07:19:43 am
  14. X-Mailer: ELM [version 2.4 PL24]
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMWAi80y4NqrwXLNJAQH8nwH+OKO96ZsqsvD/BJkwYiVkBHP7YktjPqvR
  17.     5pts1Q0yPxOjq5ZM6UVnMARUe2wohkJzNEUffemAeV/D6bVBpIjyEg==
  18.     =xtmN
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. > Being const means only that the current function won't change the
  22. > object, not that the object itself won't change during the function.
  23. > It could change as the result of a side effect of another function
  24. > called within the current one.
  25.  
  26. A non-const object can be changed any time its name or a non-const
  27. pointer is in scope, through the name or pointer; this behaviour
  28. is not surprising.  But as I understand it, there is no
  29. dispensation to modify it through a const-pointer, which includes
  30. "this".
  31.  
  32. > Thus unless only inline or other internally known functions are
  33. > called, no additional optimizations are possible.
  34.  
  35. True, but only for the reason above, which is the same reason you
  36. can't optimise away function calls in general.
  37.  
  38. What are needed (to allow some function calls to be optimised
  39. away) are two new keywords:
  40.  
  41.   * "clean" which guarantees that the function doesn't modify
  42.     objects that can only be reached as or through names
  43.     in an outer scope - and in turn will not call any non-clean
  44.     functions; and
  45.  
  46.   * "pure" which guarantees that the function does not depend on
  47.     the value of any outer scope object - and in turn will not
  48.     call any non-pure function;
  49.  
  50. To be fully useful, a function would be declared with both of
  51. these attibutes and with all pointer or reference parameters
  52. (including "this") declared "const".
  53.  
  54. Anyone care to put this forward, or has it been discussed before?
  55. ---
  56. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  57.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  58.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  59.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  60.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  61. ]
  62.